package com.yc.order.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClientConfiguration;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

//对每个服务分别指定负载均衡策略
@LoadBalancerClients(
        value = {
                @LoadBalancerClient(value = "freshgood-cart",configuration = RoundRobinConfig.class),
//                @LoadBalancerClient(value = "cloud-security",configuration = RandomConfig.class),
        },defaultConfiguration = LoadBalancerClientConfiguration.class
)
public class LoadBalancerConfig {
    @LoadBalanced //开启RestTemplate 对象的负载均衡器功能
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
